#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t pid = fork();
    if(pid < 0)
    {
        perror("fork");
        exit(1);
    }
    else if(pid == 0)
    {
        int cnt = 5;
        while(cnt--)
        {
            printf("cnt: %d ,i am child, pid: %d, getpid: %d\n",cnt,getpid(),getppid());
            sleep(1);
         }
        exit(105);
    }
    else 
    {

        printf("i am father, pid: %d, getpid: %d\n",getpid(),getppid());
        int status = 0;
        pid_t ret = waitpid(pid,&status,0);
   //     pid_t ret = wait(NULL);
        if(ret > 0)
        {
            printf("等待子进程成功,ret: %d,子进程收到的信号编号：%d, status:%d\n",ret,status & 0x7f,(status>>8)&0xFF);//阻塞式的等待
        }
   //     while(1)
   //     {
   //         
   //         printf("i am parent, pid: %d, getpid: %d\n",getpid(),getppid());
   //    sleep(1);
   //     }
    }


    return 0;
}
